import {
  ApiRootUrl,
  apiList
} from '../../config/index.js'
import Dialog from '../../@vant/weapp/dialog/dialog';
import {
  IMG_PATH
} from '../../config/index.js'
import {
  request
} from "../../utils/util.js"
import Toast from '../../@vant/weapp/toast/toast';
//获取应用实例
const app = getApp()
Page({
  data: {
    active: 0,
    loadingFlag: false,
    userInfo: {},
    topbg:"rgba(0,0,0,0)",
    width:wx.getSystemInfoSync().windowWidth,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    //绑定宫格图片地址和文字
    dataList: [],
    customFlag: false,
    value: '',
    infoList: [],
    imageurlList: [],
    statusBarHeight: ''
  },
  onLoad: function () {
    this.setData({
      statusBarHeight: wx.getSystemInfoSync()['statusBarHeight']
    })
  },
  getCount(dataList){
    request(apiList.queryEmployeeWaitCount,{}).then(res =>{
      let obj = res.data;
      dataList[1].count = obj.entryCount+"";
      dataList[0].count = obj.interviewCount+"";
      this.setData({
        dataList: dataList,
      })
      console.log(this.data.dataList);
    }).catch(err =>{
      Toast({
        duration: 3000,
        forbidClick: true,
        type: 'fail',
        message: err.message,
      });
    })
  },
  backClick(event) {
    console.log(event);
    wx.navigateBack();
    // Dialog.confirm({
    //   title: '返回',
    //   message: '请确认是否返回？',
    // }).then(() => {
    //   wx.navigateBack();
    // }).catch(() => {
    //   console.log('取消')
    // });
  },
  onChange(event) {
    console.log(event.detail)
    if (event.detail == 2) {
      console.log("点击新建")
    } else {
      this.setData({
        active: event.detail
      });
    }

  },
  newAddTap(event) {
    console.log("点击新建")
  },
  getGirdsCounts() {
    request(apiList.getGirdsCounts, {}, "GET").then(res => {
      let data = res.data;

    }).catch(err => {
      Toast({
        duration: 3000,
        forbidClick: true,
        type: 'fail',
        message: err.message,
      });
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let dataList = [{
      imgUrl: `/icon/daimianshi.png`,
      textValue: '待面试',
      navigateUrl: "../company/pendinginterview/pendinginterview",
      count: '0'
    }, {
      imgUrl: `/icon/dairuzhi.png`,
      textValue: '待入职',
      navigateUrl: "../company/entry/entry",
      count: '0'
    }, {
      imgUrl: `/icon/zaishi.png`,
      textValue: '在职人员',
      navigateUrl: "../company/onjob/onjob",
      count: '0'
    }, {
      imgUrl: `/icon/lisu.png`,
      textValue: '离宿人员',
      navigateUrl: "../company/checkout/checkout",
      count: '0'
    }, {
      imgUrl: `/icon/lizhi.png`,
      textValue: '离职人员',
      navigateUrl: "../company/resign/resign",
      count: '0'
    },{
      imgUrl: `/icon/weimianshi.png`,
      textValue: '未面试',
      navigateUrl: "../company/notInterview/index",
      count: '0'
    }
    , {
      imgUrl: `/icon/weiji.png`,
      textValue: '违纪人员',
      navigateUrl: "",
      count: '0'
    }
    // , {
    //   imgUrl: `/icon/weiji.png`,
    //   textValue: '外协人员',
    //   navigateUrl: "../company/waixieview/waixieview",
    //   count: '0'
    // }
  ];
    let imageurlList = [{
      id: '1',
      url: `${IMG_PATH}/center/qiyerenyuan.png`
    }, {
      id: '2',
      url: `${IMG_PATH}/center/qiyerenyuan.png`
    }, {
      id: '3',
      url: `${IMG_PATH}/center/qiyerenyuan.png`
    }];
    let imageurlList1 = [{
      id: '1',
      url: `${IMG_PATH}/center/qiye_banner1.png`
    }, {
      id: '2',
      url: `${IMG_PATH}/center/qiye_banner2.png`
    }]
    this.setData({
      dataList: dataList,
      imageurlList: imageurlList,
      imageurlList1:imageurlList1
    })
    this.getCount(dataList)
  },
  //点击信息触发事件
  msgTap() {
    wx.navigateTo({
      url: '../message/messagePush/messagePush',
    })
  },
  //点击搜索框触发事件
  onSearch(event) {
    Toast(`${event.detail}`);
    console.log(event)
  },
  //点击图片触发事件
  imageTab(event) {
    console.log(event.target.dataset.id);
  },
  //监听用户下拉刷新事件
  onPullDownRefresh() {
    wx.showNavigationBarLoading();
    setTimeout(function () {
      wx.hideNavigationBarLoading(); //完成停止加载图标
      wx.stopPullDownRefresh();
    }, 5000)
  },
   /**
   * 页面滑动监听
   */
  onPageScroll:function(e){
    console.log(e.scrollTop)
    if(e.scrollTop >10){
      this.setData({
        topbg:"#ACDAC3"
      })
    }else{
      this.setData({
        topbg:"rgba(0,0,0,0)"
      })
    }
  },
})